﻿@model Telerik.Web.Mvc.GridModel<CurrencyModel>
@using Telerik.Web.Mvc.UI
@{
    List<Nop.Core.Domain.Directory.ExchangeRate> rates = ViewBag.Rates;
    bool autoUpdateEnabled = ViewBag.AutoUpdateEnabled ?? false;
    //page title
    ViewBag.Title = T("Admin.Configuration.Currencies").Text;
}
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/Administration/Content/images/ico-configuration.png")" alt="" />
        @T("Admin.Configuration.Currencies")
    </div>
    <div class="options">
        <a href="javascript:document.CurrencySettings.submit()" class="t-button">@T("Admin.Common.Save")</a>
        <a href="@Url.Action("List", "Currency", new { liveRates = true })" class="t-button">@T("Admin.Configuration.Currencies.GetLiveRates")</a>
        <a href="@Url.Action("Create")" class="t-button">@T("Admin.Common.AddNew")</a>
    </div>
</div>
@using (Html.BeginForm("Save", "Currency", FormMethod.Post, new { name = "CurrencySettings" }))
{  
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @T("Admin.Configuration.Currencies.Fields.ExchangeRateProvider"):
            </td>
            <td class="adminData">
                @(Html.DropDownList("exchangeRateProvider", ViewBag.ExchangeRateProviders as IEnumerable<SelectListItem>))
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @T("Admin.Configuration.Currencies.Fields.CurrencyRateAutoUpdateEnabled"):
            </td>
            <td class="adminData">
                @(Html.CheckBox("autoUpdateEnabled", autoUpdateEnabled)
                )
            </td>
        </tr>
    </table>
}
<table class="adminContent">
    <tr>
        <td>
            @(Html.Telerik().Grid<CurrencyModel>()
                    .Name("currencies-grid")
                    .BindTo(Model.Data)
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.Name);
                        columns.Bound(x => x.CurrencyCode)
                            .Centered();
                        columns.Bound(x => x.Rate)
                            .Centered()
                            .Format("{0:G29}");
                        columns.Bound(x => x.IsPrimaryExchangeRateCurrency)
                                .Template(
                                    @<img alt="" src="@Url.Content("~/Administration/Content/images/active-" + item.IsPrimaryExchangeRateCurrency.ToString().ToLowerInvariant() + ".gif")" />
                                )
                                .ClientTemplate("<img alt='' src='" + Url.Content("~/Administration/Content/images/") + "active-<#= IsPrimaryExchangeRateCurrency #>.gif' />")
                                .Centered()
                                .Width(100);
                        columns.Bound(x => x.Id)
                            .Template(x => Html.ActionLink(T("Admin.Configuration.Currencies.Fields.MarkAsPrimaryExchangeRateCurrency").Text, "MarkAsPrimaryExchangeRateCurrency", new { id = x.Id }, new { @class = "t-button" }))
                            .Centered()
                            .HeaderTemplate(T("Admin.Configuration.Currencies.Fields.MarkAsPrimaryExchangeRateCurrency").Text);
                        columns.Bound(x => x.IsPrimaryStoreCurrency)
                                .Template(
                                    @<img alt="" src="@Url.Content("~/Administration/Content/images/active-" + item.IsPrimaryStoreCurrency.ToString().ToLowerInvariant() + ".gif")" />
                                )
                                .ClientTemplate("<img alt='' src='" + Url.Content("~/Administration/Content/images/") + "active-<#= IsPrimaryStoreCurrency #>.gif' />")
                                .Centered()
                                .Width(100);
                        columns.Bound(x => x.Id)
                            .Template(x => Html.ActionLink(T("Admin.Configuration.Currencies.Fields.MarkAsPrimaryStoreCurrency").Text, "MarkAsPrimaryStoreCurrency", new { id = x.Id }, new { @class = "t-button" }))
                            .Centered()
                            .HeaderTemplate(T("Admin.Configuration.Currencies.Fields.MarkAsPrimaryStoreCurrency").Text);
                        columns.Bound(x => x.Published)
                                .Template(
                                    @<img alt="" src="@Url.Content("~/Administration/Content/images/active-" + item.Published.ToString().ToLowerInvariant() + ".gif")" />
                                )
                                .ClientTemplate("<img alt='' src='" + Url.Content("~/Administration/Content/images/") + "active-<#= Published #>.gif' />")
                                .Centered()
                                .Width(100);
                        columns.Bound(x => x.Id)
                            .Template(x => Html.ActionLink(T("Admin.Common.Edit").Text, "Edit", new { id = x.Id }))
                            .ClientTemplate("<a href=\"Edit/<#= Id #>\">" + T("Admin.Common.Edit").Text + "</a>")
                            .Centered()
                            .HeaderTemplate(T("Admin.Common.Edit").Text);
                    })
                    .DataBinding(dataBinding => dataBinding.Ajax().Select("List", "Currency"))
                    .EnableCustomBinding(true)
                    )
        </td>
    </tr>
</table>
<p>
</p>
@if (rates != null)
{
    <h4>@T("Admin.Configuration.Currencies.LiveRates")</h4>
    <table class="adminContent" style="width: 300px">
        <tr>
            <td>
                @(Html.Telerik().Grid<Nop.Core.Domain.Directory.ExchangeRate>()
                        .Name("rate-grid")
                        .DataKeys(x =>
                        {
                            x.Add(y => y.CurrencyCode).RouteKey("CurrencyCode");
                        })
                        .BindTo(rates)
                        .Columns(columns =>
                        {
                            columns.Bound(x => x.CurrencyCode)
                                .Centered()
                                .HeaderTemplate(T("Admin.Configuration.Currencies.Fields.CurrencyCode").Text);
                            columns.Bound(x => x.Rate)
                                .Centered()
                                .HeaderTemplate(T("Admin.Configuration.Currencies.Fields.Rate").Text);
                            columns.Bound(x => x)
                                .Template(x => Html.ActionLink(T("Admin.Configuration.Currencies.ApplyRate").Text, "ApplyRate", new { rate = x.Rate, currencyCode = x.CurrencyCode }))
                                .Centered()
                                .HeaderTemplate(T("Admin.Configuration.Currencies.ApplyRate").Text)
                                .Filterable(false);

                        })
                        .EnableCustomBinding(true)
                        )
            </td>
        </tr>
    </table>
}
